require("../../utils/util.js");

var a = getApp();

Page({
    data: {
        baseUrl: a.globalData.baseUrl,
        distance: "",
        lat: "",
        lng: "",
        address: "",
        activity: [],
        serverList: [],
        orderId: "",
        imgUrls: [],
        currentTab: 0,
        order: {},
        startTime: ""
    },
    onLoad: function(t) {
        var e = this;
        e.setData({
            orderId: t.orderId
        });
        var r = a.globalData.urlBase + a.globalData.urlInvite;
        e.getinitdata(r);
    },
    getinitdata: function(t) {
        var e = this;

        wx.request({
            url: t,
            data: {
                orderId: e.data.orderId,
                lng: a.globalData.lng,
                lat: a.globalData.lat
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                console.log(t)
                if ( t.code !=0) {
                  wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                });} else {
                    var r = [], s = [], i = [];
                    i = JSON.parse(a.data).activity, console.log(i.thisUserHeadImgs);
                    for (var o = 0; o < i.num; o++) i.thisUserHeadImgs[o] ? s.push(i.thisUserHeadImgs[o]) : s.push("../../img/ndefava.png");
                    
                    r = JSON.parse(a.data).activity.imgs.split(","), e.setData({
                        activity: t.activity,
                        user: t.user,
                        store: t.store,
                        hedimg: r,
                        allUserHeadImgs: s,
                        startTime: t.activity.createTime,
                        lastTime: t.activity.lastTime,
                        lat: t.store.lat,
                        lng: t.store.lng,
                        name: t.store.name,
                        address: t.store.address,
                        activityId: t.activity.id,
                        shareName: t.activity.name ? t.activity.name : ""
                    }), e.test(e.data.startTime, e.data.lastTime);
                }
            },
            fail: function(a) {
                console.log(".....fail.....");
            }
        });
    },
    test: function(a, t) {
        var e = this, r = Date.parse(new Date(a.replace(/-/g, "/"))) / 1e3 + 60 * parseInt(t) * 60, s = setInterval(function() {
            var a = Date.parse(new Date()) / 1e3, t = r - a, i = "00", o = "00", n = "00";
            t > 0 && (n = t - 3600 * (i = Math.floor(t / 3600) < 10 ? "0" + Math.floor(t / 3600) : Math.floor(t / 3600)) - 60 * (o = Math.floor((t - 3600 * i) / 60) < 10 ? "0" + Math.floor((t - 3600 * i) / 60) : Math.floor((t - 3600 * i) / 60)) < 10 ? "0" + (t - 3600 * i - 60 * o) : t - 3600 * i - 60 * o), 
            e.setData({
                hours: i,
                minutes: o,
                seconds: n
            }), "00" == e.data.hours && "00" == e.data.minutes && "00" == e.data.seconds && clearInterval(s);
        }, 1e3);
    },
    bindChange: function(a) {
        this.setData({
            currentTab: a.detail.current
        });
    },
    openMap: function() {
        var a = this;
        wx.openLocation({
            latitude: parseFloat(a.data.lat),
            longitude: parseFloat(a.data.lng),
            name: a.data.name,
            address: a.data.address
        });
    },
    swichNav: function(a) {
        var t = this;
        if (this.data.currentTab === a.target.dataset.current) return !1;
        t.setData({
            currentTab: a.target.dataset.current
        });
    },
    inviteGroup: function(a) {
        wx.navigateTo({
            url: "../index/detail?id=" + a.currentTarget.dataset.id
        });
    },
    onShareAppMessage: function(a) {
        var t = this;
        return a.from, {
            title: t.data.shareName,
            path: "/pages/collageDetails/collageDetails?id=" + t.data.activityId + "&type=1&orderid=" + t.data.orderId + "&ctshare=1",
            imageUrl: t.data.baseUrl + "download?id=" + t.data.hedimg[0],
            desc: "",
            success: function(a) {
                console.log("转发成功:" + JSON.stringify(a));
            },
            fail: function(a) {
                console.log("转发失败:" + JSON.stringify(a));
            }
        };
    }
});